clear all

********************************************************************************


//Load data
////////////////////////////////////////////////////////////////////////////////


foreach s of numlist 108/113 200/204 {
display in red "************************ Series `s' ************************ "

import excel using "./data sheets/DATA_Series `s'.xlsx", clear sheet("Pages 1 - 2; 3") cellrange(a3) 


//Pages 1-2

***Mine info
{
rename A series
rename B year
rename C arrondissement
rename D ordernr
rename E mine_name
rename F mine_community
rename G concession_date
rename H concession_ha
rename I operations_active
rename J operations_reserve
rename K operations_construction
rename L vein_n
rename M avgvein_thickness

drop if missing(ordernr)
}

***Capital
{
rename N k_extraction_v_n
rename O k_extraction_m_n
rename P k_extraction_t_n
rename Q k_extraction_hp
rename R k_extraction_hp2
rename S k_extraction_hn
rename T k_excavation_n
rename U k_excavation_hp
rename V k_ventilation_n
rename W k_ventilation_hp
rename X k_other_n
rename Y k_other_hp
rename Z galleries_transport_n
rename AA galleries_water_n
rename AB horses_underground_n
rename AC horses_surface_n
}

***Labor
{
rename AD l_under_total_n
rename AE l_under_total_w
rename AF l_surface_total_n
rename AG l_surface_total_w
rename AH l_total_n
rename AI l_total_w
}


***Finances/Production
{
rename AJ avgprod_pit
rename AK avgprod_mine
rename AL avgdays_pit
rename AM avgdays_mine
rename AN expenses_std_l
rename AO expenses_std_other
rename AP expenses_std_total
rename AQ prixderevient_std_t
rename AR expenses_spc_l
rename AS expenses_spc_other
rename AT expenses_spc_total
rename AU expenses_l
rename AV expenses_other
rename AW expenses_total
rename AX prixderevient_t
}


//Page 3
drop AY


***Finances/Production (2)
rename AZ q_dry_t
rename BA q_dry_p
rename BB q_leans_t
rename BC q_leans_p
rename BD q_leanl_t
rename BE q_leanl_p
rename BF q_halfl_t
rename BG q_halfl_p
rename BH q_fatty_t
rename BI q_fatty_p

rename BJ q_total_t
rename BK q_total_pq
rename BL q_total_p
rename BM balance_gain
rename BN balance_loss
rename BO observations

capture rename BP consumption_t
capture rename BQ consumption_pq
capture rename BR consumption_stock


//String variables
////////////////////////////////////////////////////////////////////////////////
tostring concession_date, replace
tostring avgvein_thickness, replace



tempfile data`s'
save `data`s'', replace
}


//Merge series
////////////////////////////////////////////////////////////////////////////////


use `data108', clear
foreach s of numlist 109/113 200/204 {
display in red "** `s' **"
append using `data`s''
}

save data_108-113_200-204.dta, replace

exit





